<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.Vector, tu.java.reservation.Reservation, tu.java.utils.UIUtils, tu.java.movie.Movie, tu.java.hall.Hall"%>
    
<%@include file="template/header.jspf" %>

<%
if(!Menu.checkUserAcess(request,6)){
	response.sendRedirect(request.getContextPath());
	return;
}

Vector<Reservation> reservations = null;

if (request.getParameter("check") != null) {
	Reservation r = Reservation.searchReservations(Integer.parseInt(request.getParameter("check")), 0).get(0);
	r.changeState();
	response.sendRedirect("check.jsp?projection=" + request.getParameter("projection") + "&submit");
}

int selectedProjection = request.getParameter("projection")!=null ? Integer.parseInt(request.getParameter("projection")) : 0;
%>

<div class="content">

	<h2 id="title">Дощли за прожекцията</h2>
		
		<form action="check.jsp" method="post" id="search" name="search">
			<table class="formtable">
				<tr>
					<td align="right">Прожекция:</td>
					<td align="left">
						<select id="projection" name="projection" onchange="document.forms['search'].submit();">
							<option value="0" <%=selectedProjection==0?"selected":""%>>-Избери-</option>
							<%=UIUtils.printOptions("SELECT P.CP01_PROJECTION_ID, SUBSTRING(P.CP01_BEGIN_TIME_DATE,1,16) || '  -  ' || M.CM01_MOVIE_NAME || '  -  ' || H.CH01_HALL_NAME FROM TP01_PROJECTIONS P JOIN TM01_MOVIES M ON P.CM01_MOVIE_ID = M.CM01_MOVIE_ID JOIN TH01_HALLS H ON P.CH01_HALL_ID = H.CH01_HALL_ID", selectedProjection)%>
						</select>
					</td>
				</tr>
			</table>
		</form>
		
		
		
		<% 
			if (request.getParameter("projection")!=null) {
								
				reservations = Reservation.searchReservationsForProjection(selectedProjection);
			}
		
			if (reservations != null) {
		%>

		<table class="resulttable">
			<tr>
				<th width="200">Потребител</th>
				<th width="200">Статус</th>
				<th width="100">Действие</th>
			</tr>
			<%for (int i=0; i<reservations.size(); i++) { %>
			<tr>
				<td>
					<%=reservations.get(i).getReservationUser().getEmail() 
					+ " - " + reservations.get(i).getReservationUser().getFirstName() + " " 
					+ reservations.get(i).getReservationUser().getLastName()%>
				</td>
				<td><%=reservations.get(i).getReservationState()==0 ? "Не е дошъл" : "Дошъл"%></td>
				<td>
					<a href="check.jsp?check=<%=reservations.get(i).getReservationId()%>&projection=<%=reservations.get(i).getProjectionId()%>" >
					<%=reservations.get(i).getReservationState()==0 ? "Отметни" : "Махни отметка"%></a>
				</td>
			</tr>
			<%} %>
		</table>
		<%=reservations.size()==0 ? "<div class=\"error\">Няма намерени резултати!</div>":""%>
			<%} %>

		

</div>

<%@include file="template/footer.jspf" %>